<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Demo extends Controller{
	public function demoTypeList(){
		$logo = Db::name('navigation_logo')->where('type = 2')->value('logo');
		$demoTypeList = Db::name('demotype')->field('id,name')->select();
		$allNum = 0;
		foreach ($demoTypeList as $key => &$value) {
			$where['demotype'] = array('EQ',$value['id']);
			$value['num'] = Db::name('demo')->where($where)->count();
			$allNum += $value['num'];
		}
		echo json_encode(['code' => 0,'msg' => '获取成功','logo' => $logo,'allNum' => $allNum,'typeList' => $demoTypeList]);
	}
	public function getDemoList(){
		$typeid = input('post.typeid');
		if($typeid == 0){
			$where['demotype'] = array('NEQ',0);
		}else{
			$where['demotype'] = array('EQ',$typeid);
		}
		$page = input('post.page');
		if(empty($page)){
			$page = 1;
		}
		$limit = input('post.limit');
		if(empty($limit)){
			$limit = 12;
		}
		$limit_one = ($page - 1) * $limit;
		$limit_two = ($page - 1) * $limit + $limit;
		$listNum = Db::name('demo')->field('id,logo,title,introduce')->where($where)->count();
		$sumPage = ceil($listNum / $limit);
		$demoList = Db::name('demo')->field('id,logo,title,introduce')->where($where)->limit($limit_one,$limit_two)->select();
		echo json_encode(['code' => 0,'msg' => '获取成功','demoList' => $demoList,'page' => $page,'sum_page' => $sumPage]);
	}
	// 案例详情
	public function demoInfo(){
		$did = input('post.id');
		if(empty($did)){
			echo json_encode(['code' => 1,'msg' => '缺少案例id']);
			exit;
		}
		$info = Db::name('demo')->where('id = '. $did)->find();
		if(!empty($info)){
			echo json_encode(['code'=> 0,'msg'=> '获取成功','data' => $info]);
		}else{
			echo json_encode(['code' => 1,'msg' => '获取失败']);
		}
	}
}